Field of the Invention
The present invention relates to an electronic device and a method of motion processing. More particularly, the present invention relates to an electronic device and a method that handle the samples used in numerical integration for motion processing.
Description of the Related Art
Some modern consumer electronic devices, such as smart phones, can be used as remote controls for controlling home appliances, or be used as user interfaces for interacting with game consoles. Alternatively, some consumer electronic devices can execute applications or games responsive to movements and/or rotations of the electronic devices themselves. In such applications, the user can issue a command by moving or rotating such an electronic device. Such an electronic device includes a motion sensor to detect the movement and/or rotation of the electronic device itself. For example, the motion sensor may be a gyroscope that detects the angular velocity of the rotation of the electronic device. The central processing unit (CPU) of the electronic device can calculate the rotation or the orientation of the electronic device by performing a numerical integration based on the sampled angular velocities of the electronic device.
FIG. 1 is a schematic diagram showing the sampling and the numerical integration of a conventional motion processing of the aforementioned electronic device. The curve 110 represents the angular velocity of the electronic device. The motion sensor of the electronic device samples the angular velocity periodically. The samples are represented as round dots on the curve 110, such as the samples 112, 114 and 116. The area between the angular velocity curve 110 and the time axis means the amount of the rotation of the electronic device. The CPU of the electronic device uses the samples of the angular velocity to perform a numerical integration to get an approximation of the area, and then the CPU interprets the result as a command input by the user or a state of the electronic device, for further motion processing.
The CPU may perform the numerical integration by accumulating the areas of the trapezoids defined by the samples, such as the trapezoid 120 defined by the samples 112 and 114. Inevitably, there is an accumulated error between the real angular velocity curve and the trapezoids. For example, the shaded area 130 is a part of the accumulated error, which is between the real curve 110 and the trapezoid 120. The smaller the accumulated error, the more accurate the numerical integration.
The motion sensor samples the curve 110 according to its own clock. The CPU polls the motion sensor and fetches the samples from the motion sensor according to its own clock. The two clocks are often not in synchronization. The CPU uses the time of its own clock to calculate the numerical integration, regardless of the actual sampling time of the samples, which results in incorrect areas of the trapezoids and enlarges the accumulated error. Even when the two clocks are synchronized, sometimes the CPU is too engaged in other tasks to fetch the samples from the motion sensor at the right moments, which also contributes to the accumulated error.
One way to solve the synchronization problem is using interrupt to notify the CPU of new samples to be fetched. However, this solution requires the CPU to provide a dedicated pin for receiving the interrupt signal from the motion sensor, which is often impractical because the pins of the CPU are precious resources.
The CPU polls the motion sensor periodically. The CPU fetches one sample from the motion sensor in each polling. The motion sensor only keeps the latest sample. The polling rate of the CPU is often lower than the sampling rate of the motion sensor. For example, the motion sensor may sample the curve 110 every one millisecond (ms), while the CPU may poll the motion sensor every ten milliseconds. In this case, the CPU gets only one tenth of the samples produced by the motion sensor. Ideally, the polling rate for the CPU should be as high as possible because more samples means the upper envelope of the trapezoids can approach the curve 110 to reduce the accumulated error. However, the CPU has other tasks to do in addition to polling the motion sensor, such as executing applications and refreshing the display of the electronic device. The CPU can be too busy in communicating with the motion sensor to perform the other tasks when the polling rate for the CPU is too high.